﻿using System;
using System.Windows.Controls;
using System.Windows;
using DiagramDesigner.BusinessModelObject;
using System.Windows.Input;

namespace DiagramDesigner
{
    public class GUIElement:UserControl
    {
        public DesignerItem DesigItem
        {
            get; set;
        }

        protected void ItemSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var win = (Window1)Window.GetWindow(this);
            var lst = (ListView)sender;
            var atributos = ((MainElementModel)DesigItem.Item).Atributos;
            if (DesigItem != null && DesigItem.Item != null && atributos.ContainsKey(lst.SelectedIndex))
            {
                var attribute = atributos[lst.SelectedIndex];
                var at = Convert.ChangeType(attribute, attribute.GetType());
                if (win != null) win.ucProperties.ShowProperties(DesigItem, at);
            }
        }

        protected void imgSourceMouseDown(object sender, MouseButtonEventArgs e)
        {
            var win = (Window1)Window.GetWindow(this);
            var atributos = ((MainElementModel)DesigItem.Item).Atributos;
            if (atributos.Count == 0) return;

            var attribute = atributos[-1];
            var at = Convert.ChangeType(attribute, attribute.GetType());
            if (win != null) win.ucProperties.ShowProperties(DesigItem, at);
        }   

    }
}
